package com.base.myproject.client.HR.Self;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.LasyObejct;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseGridPanel;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;

public class SelfBcode_job_his extends LayoutContainer implements LasyObejct{
	BaseStore<BusiObject> mainstore = null;
	
	String bcode;
	BaseGrid grid = null;
	
	java.util.Date currentTime = new java.util.Date();
	Date df_date = new Date();

	public SelfBcode_job_his(BaseStore<BusiObject> mainstore){
		this.mainstore = mainstore;
		this.setStyleAttribute("background-color", "#DFE8F6");
		//this.setWidth(1024);
		init();
	}

	private void init() { 
		FieldSet fs1 = new FieldSet();
		fs1.setHeading("员工变动记录");
		//fs1.setStyleName("firldset_css1");
		fs1.add(createGrid());
		FieldSet fs2 = new FieldSet();
		fs2.setHeading("早前工作记录");
		//fs2.setStyleName("firldset_css1");
		fs2.add(create_job_his_a_Grid());
		VerticalPanel v = new VerticalPanel();
		v.setSpacing(2);
		v.add(fs1);
		v.add(fs2);
		this.add(v);
	}

	BaseStore<BusiObject> store = null;

	BaseStore<BusiObject> getStore() {
		if (store == null) {
			createStore();
		}
		return store;
	}

	BaseStore<BusiObject> createStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("ChangeType");
		type.getField("ChangeType").setType(String.class);
		type.addField("ChangeDate");
		type.getField("ChangeDate").setType(Date.class);
		type.addField("availableDate");
		type.getField("availableDate").setType(Date.class);
		type.addField("before");
		type.getField("before").setType(String.class);
		type.addField("after");
		type.getField("after").setType(String.class);
		type.addField("remark");
		type.getField("remark").setType(String.class);
		type.addField("whether_continue");
		type.getField("whether_continue").setType(Boolean.class);
		type.addField("Notes");
		type.getField("Notes").setType(String.class);
		
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_EmployeeChange");
		info.setKeyname(new String[]{ "icode" });
		info.setSql("select * from hr_EmployeeChange where bcode='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
		store = new BaseStore<BusiObject>(type,info);
		return store;
	}
	
	BaseStore<BusiObject> store2 = null;

	BaseStore<BusiObject> getStore2() {
		if (store2 == null) {
			createStore2();
		}
		return store2;
	}

	BaseStore<BusiObject> createStore2() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("employlevel");
		type.getField("employlevel").setType(String.class);
		type.addField("employinnertitle");
		type.getField("employinnertitle").setType(String.class);
		type.addField("employstatus");
		type.getField("employstatus").setType(String.class);
		type.addField("jobgroup");
		type.getField("jobgroup").setType(String.class);
	
		
		StoreInfo info = new StoreInfo();
		info.setTablename("bcode_job");
		info.setKeyname(new String[]{ "icode" });
		info.setSql("select icode,bcode,employlevel,employinnertitle,employstatus,jobgroup from bcode_job where bcode='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
		store2 = new BaseStore<BusiObject>(type,info);
		return store2;
	}
	
	
	
	public BaseGrid createGrid(){
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		ColumnConfig changetype = new ColumnConfig("ChangeType", "变动类型", 60);
	    ColumnConfig availabledate = new ColumnConfig("availableDate", "生效日期", 80);
	    availabledate.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	    
	    ColumnConfig before = new ColumnConfig("before", "变动前", 90);
	    ColumnConfig after = new ColumnConfig("after", "变动后", 90);
	    ColumnConfig remark = new ColumnConfig("remark", "变动原因", 60);
	    ColumnConfig Notes = new ColumnConfig("Notes", "备注", 150);
	    
		columns.add(changetype);
		columns.add(availabledate);
		columns.add(before);
		columns.add(after);
		columns.add(remark);
		columns.add(Notes);
		ColumnModel cm = new ColumnModel(columns);
		
		grid = new BaseGrid(getStore(), cm, false, false);
		grid.setSize(760, 200);
		return grid;
	}
	
	BaseStore<BusiObject> jobhis_a_store = null;

	public BaseStore<BusiObject> getJobhis_a_store() {
		if (jobhis_a_store == null) {
			create_job_his_a_Store();
		}
		return jobhis_a_store;
	}

	BaseStore<BusiObject> create_job_his_a_Store() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("startdate");
		type.getField("startdate").setType(Date.class);
		type.addField("enddate");
		type.getField("enddate").setType(Date.class);
		type.addField("companyname");
		type.getField("companyname").setType(String.class);
		type.addField("title");
		type.getField("title").setType(String.class);
		type.addField("salary_rmb");
		type.getField("salary_rmb").setType(Double.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("bcode_job_his_a");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from bcode_job_his_a where bcode ='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		 info.setLinkparent_chile_columns(new String[] { "bcode" });//
		// 关联主表字段
		jobhis_a_store = new BaseStore<BusiObject>(type, info);
		return jobhis_a_store;
	}

	BaseGrid jobhis_a_grid = null;

	BaseGrid create_job_his_a_Grid() {
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

		ColumnConfig C3 = new ColumnConfig("startdate", "开始日期", 100);
		DateField dateField3 = new DateField();  
		dateField3.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
		C3.setEditor(new CellEditor(dateField3));
		C3.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("enddate", "结束日期", 100);
		DateField dateField4 = new DateField();  
		dateField4.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
		C4.setEditor(new CellEditor(dateField4));
		C4.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C4);
		ColumnConfig C5 = new ColumnConfig("companyname", "公司名称", 200);
		C5.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C5);
		ColumnConfig C6 = new ColumnConfig("title", "职位", 100);
		C6.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C6);
		ColumnConfig C7 = new ColumnConfig("salary_rmb", "薪金", 100);
		C7.setNumberFormat(NumberFormat.getCurrencyFormat());  
		C7.setEditor(new CellEditor(new NumberField()));  
		
		columns.add(C7);

		ColumnModel cm = new ColumnModel(columns);
		jobhis_a_grid = new BaseGrid(create_job_his_a_Store(), cm, false, false);
		jobhis_a_grid.setSize(760, 150);
		return jobhis_a_grid;
	}
	
	@Override
	public boolean isopen() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean open() {
		// TODO Auto-generated method stub
		return false;
	}
}
